<%@page import="com.crm.util.Pager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>员工资源转移</title>
	<% request.setAttribute("menu", 1); %>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
    <link rel="stylesheet" href="<%=basePath%>plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="<%=basePath%>css/global.css" media="all" />
    <link rel="stylesheet" href="<%=basePath%>plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/tab.css" media="all" />
    
    <style type="text/css">
		.trans_tc,.transmore_tc,.transall_tc {display: none;}
		.wybsf p { margin-top: 8px; }
    </style>
    
</head>
<body>


<div class="admin-tab admin-user admin-transform">
    <div class="tab-condition">
        <form class="layui-form clefix" action="/customer/transurl" method="post" id="transformform">
            <div class="layui-form-item">
            	<div class="layui-input-inline">
	                  	<input type="text" name="keyWord" id="keyWord" class="layui-input" placeholder="请输入关键字"  style="width:100%" value="${pager.params.keyWord}"> 
	            </div>
            	<div class="layui-input-inline">
                    <select name="state" id="state" lay-filter="state" class="stateclass">
                    	<option value="">请选择成熟等级</option>
                    	<option value="-1" <c:if test="${pager.params.state == -1}">selected</c:if>>全部</option>
                    	<c:if test="${pager.params.type==null || pager.params.type == -1}">
                    		<option value="1" <c:if test="${pager.params.state == 1}">selected</c:if>>意向不明</option> 
                    		<optgroup label="企业">
						    	<option value="6" <c:if test="${pager.params.state == 6}">selected</c:if>>意向明确</option>
                       			<option value="5" <c:if test="${pager.params.state == 5}">selected</c:if>>意向强烈</option> 
							</optgroup>
	                    	<optgroup label="个人">
							    <option value="0" <c:if test="${pager.params.state == 0}">selected</c:if>>最新资源</option>
							    <option value="2" <c:if test="${pager.params.state == 2}">selected</c:if>>意向明确</option>
							    <option value="3" <c:if test="${pager.params.state == 3}">selected</c:if>>意向强烈</option> 
							</optgroup>
							  <option value="7" <c:if test="${pager.params.state == 7}">selected</c:if>>合作客户</option>  
                    	</c:if>
                    	<c:if test="${pager.params.type == 1}">
                    			<option value="1" <c:if test="${pager.params.state == 1}">selected</c:if>>意向不明</option> 
						    	<option value="6" <c:if test="${pager.params.state == 6}">selected</c:if>>意向明确</option>
                       			<option value="5" <c:if test="${pager.params.state == 5}">selected</c:if>>意向强烈</option>
                       			<option value="7" <c:if test="${pager.params.state == 7}">selected</c:if>>合作客户</option>  
                    	</c:if>
                    	<c:if test="${pager.params.type == 0}">
                    		    <option value="1" <c:if test="${pager.params.state == 1}">selected</c:if>>意向不明</option> 
							    <option value="0" <c:if test="${pager.params.state == 0}">selected</c:if>>最新资源</option>
							    <option value="2" <c:if test="${pager.params.state == 2}">selected</c:if>>意向明确</option>
							    <option value="3" <c:if test="${pager.params.state == 3}">selected</c:if>>意向明确</option>
							    <option value="7" <c:if test="${pager.params.state == 7}">selected</c:if>>合作客户</option>  
                    	</c:if>
                    	
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="type" id="type" lay-filter="type" class="typeclass">
                        <option value="">请选择类别</option>
                        <option value="-1" <c:if test="${pager.params.type == -1}">selected</c:if>>全部</option>
                        <option value="1" <c:if test="${pager.params.type == 1}">selected</c:if>>企业</option>
                        <option value="0" <c:if test="${pager.params.type == 0}">selected</c:if>>个人</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="boutique" >
                    	<option value="">请选择资源类型</option>
                    	<option value="-1" <c:if test="${pager.params.boutique == -1}">selected</c:if>>全部</option>
                        <option value="1" <c:if test="${pager.params.boutique == 1}">selected</c:if>>精品资源</option>
                        <option value="0" <c:if test="${pager.params.boutique == 0}">selected</c:if>>普通资源</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="uid" >
                    	<option value="">请选择用户</option>
                    	<option value="-1" <c:if test="${ -1 == pager.params.uid }">selected</c:if> >全部</option>
                    	<c:forEach var="nameobj" items="${userlist}">
                    		<option value="${nameobj.uid}" <c:if test="${ nameobj.uid == pager.params.uid }">selected</c:if> >${nameobj.name}</option>
                    	</c:forEach>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
            	<input name="skipToPage" id="skipToPage"  type="hidden" value="${pager.pageNo}">
				<input type="hidden" id="pageNo" name="pageNo" value="${pager.pageNo}">
				<input type="hidden" id="totalPage" name="totalPage" value="${pager.totalPages}">
				<input type="hidden" id="pageSize" name="pageSize" value="${pager.pageSize}">
				<input type="hidden" id="olduid" name="olduid" value="${pager.params.uid}">
                <button class="layui-btn search" type="button" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i>搜索</button>
                <button class="layui-btn clean" type="button" lay-submit="" lay-filter="clean"><i class="layui-icon">&#xe640;</i>清空</button>
            </div>
        </form>
        <div class="TM-tab-info">
            <a class="layui-btn layui-btn-primary layui-btn-small active transall">+全部转移</a>
            <a class="layui-btn layui-btn-primary layui-btn-small transsome">+部分转移</a>
            <a class="layui-btn layui-btn-primary layui-btn-small trans">+转移</a>
         <c:if test="${sessionScope.user.id==1}">   
         <a class="layui-btn layui-btn-primary layui-btn-small fqbtn"><i class="layui-icon">&#x1006;</i>批量删除</a>
         </c:if>
            <a class="layui-btn layui-btn-primary layui-btn-small refreshbtn"><i class="layui-icon">&#x1002;</i>刷新</a>
        </div>
    </div>
    <div class="layui-field-box">
        <table class="site-table table-hover TM-user TM-table3">
            <thead>
            <tr>
                <th style="width:10px;"><input type="checkbox" id="selected-all"/></th>
                <th style="width:200px;">资源名称</th>
                <th style="width:150px;">类别</th>
                <th style="width:170px;">所有人</th>
                <th style="width:170px;">成熟等级</th>
                <th style="width:225px;">最后跟进时间</th>
                <th style="width:165px;">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach var="obj" items="${pager.resultList}">
	            <tr data="${obj.id}">
	                <td><input type="checkbox" name="select-all-cbox" value="${obj.id}"/></td>
	                <td>
	                <a class="TM_hover co-address" href="#">
	                 <c:if test="${obj.boutique !=null && obj.boutique==1}">
					    [<span style="color:#007eff">精</span>]
					  </c:if>
	                ${obj.cname}
	                </a>
	                </td>
	                <td>${obj.type  == 0 ? '个人' : '企业'}</td>
	                <td>${obj.name}</td>
	                <td><dic:cf value="${obj.state}" name="customer_state" type="1"/></td>
	                <td class="TM_hover seenote seenote${obj.id}" data="${obj.id}">${obj.updatedate.substring(0,10)}  ${obj.updatedate.substring(10,19)}</td>
                	<td>
                		<c:if test="${obj.boutique !=null && obj.boutique==1}">
					      <a href="#" class="layui-btn layui-btn-normal layui-btn-mini transform-btnupd">灭精</a>
					    </c:if>
					    <c:if test="${obj.boutique ==null || obj.boutique==0}">
					      <a href="#" class="layui-btn layui-btn-normal layui-btn-mini transform-btnupd1">设精</a>
					    </c:if>
                		<a href="#" class="layui-btn layui-btn-normal layui-btn-mini transform-btn">转移</a>
                		<a href="#" class="layui-btn layui-btn-normal layui-btn-mini find-btn">查看</a>
                	</td>
            	</tr>
            </c:forEach>
            
            </tbody>
        </table>
        <div class="admin-table-page">
							<div class="page">
								<div class="layui-laypage">
									<span class="layui-laypage-total"><button type="button"
											class="layui-laypage-btn">共${pager.totalSize}条记录</button></span>
								</div>
							</div>
		 </div>
        <div class="admin-table-page">
            <div id="page" class="page"></div>
        </div>
    </div>
    
    
    <!-- 一条,多条选择转移 -->
    <div class="trans_tc">
    	<form action="" id="trans_form"  class="layui-form" >
    		<%-- <div class="layui-form-item">
	            <label class="layui-form-label">持有人 :</label>
	            <div class="layui-input-inline" >
	                   <select name="olduids" id="olduids" lay-filter="uids">
							<c:forEach var="nameobj" items="${userlist}">
								<option value="${nameobj.uid}">${nameobj.name}</option>
							</c:forEach>
						</select>
	             </div>
             </div> --%>
    		<div class="layui-form-item">
	            <label class="layui-form-label">转移给 :</label>
	            <div class="layui-input-inline" >
	                   <select name="uid" id="uids" lay-filter="uids">
							<c:forEach var="nameobj" items="${userlist}">
								<c:if test="${nameobj.uid != pager.params.uid}">
									<option value="${nameobj.uid}">${nameobj.name}</option>
								</c:if>
							</c:forEach>
						</select>
	             </div>
             </div>
		</form>
    </div>
    
    <!-- 全部转移 -->
    <div class="transall_tc">
    	<form action="" id="transall_form"  class="layui-form" >
    		<div class="layui-form-item">
	            <label class="layui-form-label">持有人 :</label>
	            <div class="layui-input-inline" >
	                   <select name="olduids" id="allolduids" lay-filter="uids">
							<c:forEach var="nameobj" items="${userlist}">
								<option value="${nameobj.uid}">${nameobj.name}</option>
							</c:forEach>
						</select>
	             </div>
             </div>
    		<div class="layui-form-item">
	            <label class="layui-form-label">转移给 :</label>
	            <div class="layui-input-inline" >
	                   <select name="uid" id="alluids" lay-filter="uids">
							<c:forEach var="nameobj" items="${userlist}">
								<c:if test="${nameobj.uid != pager.params.uid}">
									<option value="${nameobj.uid}">${nameobj.name}</option>
								</c:if>
							</c:forEach>
						</select>
	             </div>
             </div>
		</form>
    </div>
    
    <!-- 多页转移 -->
    <div class="transmore_tc">
    	<form action="" id="transmore_form"  class="layui-form" >
    		
    		<div class="layui-form-item">
            	<label class="layui-form-label"><span>说明 : </span></label>
                <div class="layui-input-inline wybsf">
                	<p class="wybsf_p">资源共：${pager.totalPages}页，每页：${pager.pageSize}条</p>
                </div>
            </div>
            <div class="layui-form-item">
	            <label class="layui-form-label">持有人 :</label>
	            <div class="layui-input-inline" >
	                   <select name="olduids" id="olduidss" lay-filter="olduids">
							<c:forEach var="nameobj" items="${userlist}">
								<option value="${nameobj.uid}">${nameobj.name}</option>
							</c:forEach>
						</select>
	             </div>
             </div>
            <div class="layui-form-item">
            	<label class="layui-form-label"><span>资源类型 : </span></label>
                <div class="layui-input-inline">
                	<select name="custype" id="custype" lay-filter="custype">
			    		<option value="-1"<c:if test="${pager.params.type == -1}">selected</c:if>>全部</option>
						<option value="0"<c:if test="${pager.params.type == 0}">selected</c:if>>个人</option>
						<option value="1"<c:if test="${pager.params.type == 1}">selected</c:if>>企业</option>
					</select>
                </div>
            </div>
    		<div class="layui-form-item">
            	<label class="layui-form-label"><span>起始页数 : </span></label>
                <div class="layui-input-inline">
                	<select name="startpage" id="startpage" lay-filter="lay-filter">
                		<option value="">请选择</option>
                		
                		 <c:if test="${  pager.params.uid>0 }">
                		 	<c:if test="${pager.totalPages > 1}">
	                		<c:forEach begin="0" end="${pager.totalPages-1}" var="objs" varStatus="o1">
	                			<option value="${o1.index+1}">${o1.index+1}</option>
	                		</c:forEach>
	                		</c:if>
	                		<c:if test="${pager.totalPages == 1}">
	                			<option value="1">1</option>
	                		</c:if>
                		 </c:if>
                		
                		
                	</select>
                </div>
            </div>
            <div class="layui-form-item">
            	<label class="layui-form-label"><span>结束页数 : </span></label>
                <div class="layui-input-inline">
                	<select name="endpage" id="endpage" lay-filter="lay-filter">
                		<option value="">请选择</option>
                		 <c:if test="${  pager.params.uid>0 }">
	                		<c:if test="${pager.totalPages > 1}">
		                		<c:forEach begin="0" end="${pager.totalPages-1}" var="objs" varStatus="o1">
		                			<option value="${o1.index+1}">${o1.index+1}</option>
		                		</c:forEach>
	                		</c:if>
	                		<c:if test="${pager.totalPages == 1}">
	                			<option value="1">1</option>
	                		</c:if>
                		</c:if>
                	</select>
                </div>
            </div>
    		<div class="layui-form-item">
    			<label class="layui-form-label">转移给 :</label>
    			<div class="layui-input-inline" >
	                   <select name="uid" id="uidss" lay-filter="uidss">
							<c:forEach var="nameobj" items="${userlist}">
								<option value="${nameobj.uid}">${nameobj.name}</option>
							</c:forEach>
						</select>
	             </div>
    		</div>
    	</form>
    </div>
    
</div>

<div class="Mask ZZmask"></div>
<script>

	layui.use(['icheck','element','laypage','form','laydate'],function(){
		
		var $ = layui.jquery,
        layer = layui.layer,
        laypage = layui.laypage;
        var form = layui.form();
        form.render();
        //input的全选与取消全选
        $("#selected-all").on("click",function(){
        	if ($("#selected-all").is(":checked")){
        		$("[name='select-all-cbox']").prop("checked",true);
        	} else {
        		$("[name='select-all-cbox']").prop("checked",false);
        	}
        });
        
        
      //移上去查看联系方式
    	$(document).on("mouseover",".seenote",function(){
    		layer.closeAll();
    		var data = $(this).attr("data");
    		//layer.msg("测试一下"+data);
    		var ele = $(".seenote"+data);
    		$.ajax({
    			type : "post",
    			url : "/customer/customercontactsbycusid",
    			data : {id : data},
    			dataType : "json",
    			async: false,
    			contentType: "application/x-www-form-urlencoded; charset=utf-8",
    			success : function(data){
    				
    				var jsondata = eval(data);
    				var html = "";
    				if (jsondata.length > 0) {
    					$.each(data, function (i, item) {
        		        	html += "["+ item.updatedate.substring(0,10) +"]"+item.remark+"------"+item.uname+"<br/>";
        		        });
    				} else {
    					html = "该数据暂无联系记录";
    				}
    				layer.tips(html, ele, {
    					tips: [1,'#f7625e'],
    					area:["400px"],
    					time:5000,
    					
    	     		 tipsMore: true
    	     		});
    			}
    		})
    	});
        
        
        var pageNo = $("#pageNo").val();
    	var totalPage = $("#totalPage").val();
		//分页按钮
    	laypage({
            cont: 'page',
            curr: pageNo//'${pager.pageNo}'
            ,pages: totalPage//'${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            skip: true,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#transformform").submit();
                }
            }
        }); 
        
		//点击搜索
		$(".search").on("click",function(){
			$("#pageNo").val(1);
			$("#skipToPage").val(1);
			$("#transformform").submit();
		});
		
		//点击清空
		$(".clean").on("click",function(){
			$("#type").val("");
			$("#state").val("");
			$("#uid").val("");
			$("#category").val("");
			form.render();
			//$("#transformform").submit();
		});

		//放弃按钮（多个）
		$(".fqbtn").on("click",function(){
			
			var id = $(this).attr("data");
			
			var value;
			//利用.each获取
			$("input:checkbox[name='select-all-cbox']:checked").each(function(i){
				if (i == 0) {
					value = $(this).val();
				} else {
					value += ","+$(this).val();
				}
			});
			if (value == null || value == "") {
				 layer.msg("请选择一条或多条记录", {icon: 0});
				 return false;
			 }
			layer.confirm('确定删除吗？', function(index){
				$.ajax({
					type : "post",
					url : "/customer/recyclebinsave",
					data : {value:value},
					dataType : "json",
					async: false,
					success : function(data){
						if (data == 1) {
							layer.msg('删除成功', {icon: 1},function(){
		   					    //	window.location.href=url;
								window.location.reload();
							});
						} else {
							layer.msg('删除失败', {icon: 2},function(){
		   					  
							});
						}
					}
				});
				layer.close(index);
			});   
		});
		
        //转移所有
        $(".transall").on("click",function(){
        	layer.open({
        		type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"资源转移",
		  		zIndex: 999,
		  		content: $(".transall_tc"),
		  		area:['70%','80%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			var uid = $("#uids").val();
		  			layer.confirm('确认转移全部资源吗？', {
		  			  btn: ['确定','取消'] //按钮
		  			}, function(){
		  				var uid = $("#alluids").val();
		  				var olduid = $("#allolduids").val();
		  				//加载层
		  				var loadindex = layer.load();
		  				$.ajax({
		  					type : "post",
		  					url : "/customer/transcusall",
		  					data : {uid : uid , olduid : olduid},
		  					dataType : "json",
		  					success : function(data){
		  						//关闭加载层
		  						layer.close(loadindex);
		  						layer.msg("资源转移成功",{time:700},function(){
		  							var href = "/customer/transformu"+olduid;
		  							layer.load();
		  							window.location.href = href;
				  				});
		  						
		  					}
		  				});
		  			}, function(){
		  				layer.msg("资源转移取消",{time:700},function(){
		  					layer.closeAll();
		  				});
		  			});
		  		}
        	});
        });
        
        function changeSelect(uid,type,pagesize){
        	$.ajax({
        		type : "post",
        		url : "/customer/allpagenobytype",
        		data : {uid:uid,type : type,pagesize : pagesize},
        		dataType : "json",
        		success : function(data){
					var text = "资源共："+ data +"页，每页："+ pagesize +"条";
					$(".wybsf_p").text(text);
					//更新select中的内容
					var html = "<option value=''>请选择</option>";
					for (var i = 1;i < data+1; i++) {
						html += "<option value='"+ i +"'>"+ i +"</option>"
					}
					$("#startpage").html(html);
					$("#endpage").html(html);
					form.render();
        		}
        	});
        }
        
        //资源持有人改变
        form.on('select(olduids)', function(data){
        	var uid = data.value
        	var pagesize = $("#pageSize").val(); //每页条数
        	var type = $("#custype").val();
        	changeSelect(uid,type,pagesize);
        });
        
        //类别选择改变
        form.on('select(custype)', function(data){
        	var type = data.value
        	var pagesize = $("#pageSize").val(); //每页条数
        	var uid = $("#olduidss").val();
        	changeSelect(uid,type,pagesize);
        });    
        
        
        
        
        //转移部分
		$(".transsome").on("click",function(){
			var uid = $("#olduidss").val();
			var pagesize = $("#pageSize").val();
			var type = $("#custype").val();
			changeSelect(uid,type,pagesize);
        	layer.open({
        		type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"资源转移",
		  		zIndex: 999,
		  		content: $(".transmore_tc"),
		  		area:['60%','99%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			var uid = $("#uidss").val();
		  			
		  			var startpage = $("#startpage").val();//起始页数
		  			var endpage = $("#endpage").val();//结束页数
		  			var pagesize = $("#pageSize").val(); //每页条数
		  			var type = $("#custype").val();
		  			var olduid = $("#olduidss").val();
		  			
		  			
		  			if (endpage-totalPage > 0) {
		  				layer.msg("页数输入有误：超出了总页数。")
		  				return false;
		  			}
		  			
		  			if (startpage > endpage) {
		  				layer.msg("页数选择有误：起始页不得大于结束页。")
		  				return false;
		  			}
		  			
		  			layer.confirm('确认转移资源吗？', {
			  			  btn: ['确定','取消'] //按钮
			  		}, function(){
			  			
			  			if (endpage == null || endpage == "") {
			  				layer.msg("请选择结束页数");
			  				return false;
			  			}
			  			
			  			if (startpage == null || startpage == "") {
			  				layer.msg("请选择起始页数");
			  				return false;
			  			}
			  			
			  			//加载层
		  				var loadindex = layer.load();
			  			
			  			$.ajax({
			  				type : "post",
			  				url : "/customer/transcusmore",
			  				data : {startpage : startpage ,endpage : endpage, uid : uid , pagesize : pagesize , type : type , olduid : olduid},
			  				dataType : "json",
			  				success : function(data){
			  					//关闭加载层
		  						layer.close(loadindex);
			  					if (data == 1) {
			  						layer.msg("资源转移成功",{icon: 1,time : 700},function(){
			  							var href = "/customer/transformu"+olduid;
			  							layer.load();
			  							window.location.href = href;
			  						});
			  					} else {
			  						layer.msg("资源转移失败，请重试",{time : 700},function(){
			  							layer.load();
			  							window.location.reload();
			  						});
			  					}
			  				}
			  			});
			  		}, function(){
		  				layer.msg("资源转移取消",{time:700},function(){
		  					layer.closeAll();
		  				});
			  		});
		  		}   		
        	});
        	
        });
        
        //转移选择的
		$(".trans").on("click",function(){
			//看看有哪些被选中的
			var value;
    		//利用.each获取
			$("input:checkbox[name='select-all-cbox']:checked").each(function(i){
				if (i == 0) {
					value = $(this).val();
				} else {
					value += ","+$(this).val();
				}
			});
    		if (value == null || value == '') {
    			layer.msg("请选择一条或多条资源");
    			return false;
    		}
    		
    		layer.open({
        		type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"资源转移",
		  		zIndex: 999,
		  		content: $(".trans_tc"),
		  		area:['50%','60%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			var uid = $("#uids").val();
		  			layer.confirm('确认转移资源吗？', {
		  			  btn: ['确定','取消'] //按钮
		  			}, function(){
		  				//加载层
		  				var loadindex = layer.load();
		  				$.ajax({
			  				type : "post",
			  				url : "/customer/transcusoneorsome",
			  				data : {uid : uid,cusids : value},
			  				dataType : "json",
			  				success : function(data){
			  					//关闭加载层
		  						layer.close(loadindex);
			  					layer.msg('资源转移成功', {icon: 1,time:700},function(){
			  						layer.load();
			  						window.location.reload();
			  					});
			  				}
			  			});
		  			}, function(){
		  				layer.msg("资源转移取消",{time:700},function(){
		  					layer.closeAll();
		  				});
		  			});
		  		}   		
        	});
    		
    		
			
		});

		

		
		 //资源设精
        $(".transform-btnupd1").on("click",function(){
        	//设置精品资源
        	var id = $(this).parent().parent().attr("data");
        	if (id == null || id == '') {
        		layer.msg("请选择一条资源");
        		return false;
        	}
        	var uid = $("#uids").val();
  			layer.confirm('确认设精吗？', {
  			  btn: ['确定','取消'] //按钮
  			}, function(){
  				//加载层
  				var loadindex = layer.load();
  				$.ajax({
	  				type : "post",
	  				url : "/customer/updcustomer",
	  				data : {boutique : 1,id : id},
	  				dataType : "json",
	  				success : function(data){
	  					//关闭加载层
  						layer.close(loadindex);
	  					layer.msg('设精成功', {icon: 1,time:700},function(){
	  						layer.load();
	  						window.location.reload();
	  					});
	  				}
	  			});
  			}, function(){
  				layer.msg("取消设精",{time:700},function(){
  					layer.closeAll();
  				});
  			});
        });
        
		 //资源设精
        $(".transform-btnupd").on("click",function(){
        	//设置精品资源
        	var id = $(this).parent().parent().attr("data");
        	if (id == null || id == '') {
        		layer.msg("请选择一条资源");
        		return false;
        	}
        	var uid = $("#uids").val();
  			layer.confirm('确认灭精吗？', {
  			  btn: ['确定','取消'] //按钮
  			}, function(){
  				//加载层
  				var loadindex = layer.load();
  				$.ajax({
	  				type : "post",
	  				url : "/customer/updcustomer",
	  				data : {boutique : 0,id : id},
	  				dataType : "json",
	  				success : function(data){
	  					//关闭加载层
  						layer.close(loadindex);
	  					layer.msg('灭精成功', {icon: 1,time:700},function(){
	  						layer.load();
	  						window.location.reload();
	  					});
	  				}
	  			});
  			}, function(){
  				layer.msg("取消灭精",{time:700},function(){
  					layer.closeAll();
  				});
  			});
        });
        
        //资源后面的转移按钮
        $(".transform-btn").on("click",function(){
        	//要被转移的客户id
        	var id = $(this).parent().parent().attr("data");
        	if (id == null || id == '') {
        		layer.msg("请选择一条或多条资源");
        		return false;
        	}
        	//打开弹窗
        	layer.open({
        		type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"资源转移",
		  		zIndex: 999,
		  		content: $(".trans_tc"),
		  		area:['50%','60%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			var uid = $("#uids").val();
		  			layer.confirm('确认转移资源吗？', {
		  			  btn: ['确定','取消'] //按钮
		  			}, function(){
		  				//加载层
		  				var loadindex = layer.load();
		  				$.ajax({
			  				type : "post",
			  				url : "/customer/transcusoneorsome",
			  				data : {uid : uid,cusids : id},
			  				dataType : "json",
			  				success : function(data){
			  					//关闭加载层
		  						layer.close(loadindex);
			  					layer.msg('资源转移成功', {icon: 1,time:700},function(){
			  						layer.load();
			  						window.location.reload();
			  					});
			  				}
			  			});
		  			}, function(){
		  				layer.msg("资源转移取消",{time:700},function(){
		  					layer.closeAll();
		  				});
		  			});
		  		}   		
        	});
        });
	});



	//点击查看
	$(".find-btn").on("click",function(){
		var id = $(this).parent().parent().attr("data");
		var url = "/customer/findcustomer"+id;
		window.open(url);
	});
	
	//移上去查看联系方式
	$(document).on("mouseover",".seenote",function(){
		layer.closeAll();
		var data = $(this).attr("data");
		//layer.msg("测试一下"+data);
		var ele = $(".seenote"+data);
		$.ajax({
			type : "post",
			url : "/customer/customercontactsbycusid",
			data : {id : data},
			dataType : "json",
			async: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			success : function(data){
				
				var jsondata = eval(data);
				var html = "";
				if (jsondata.length > 0) {
					$.each(data, function (i, item) {
    		        	html += "["+ item.updatedate.substring(0,10) +"]"+item.remark+"------"+item.uname+"<br/>";
    		        });
				} else {
					html = "该数据暂无联系记录";
				}
		        
				
				layer.tips(html, ele, {
					tips: [1,'#f7625e'],
					area:["400px"],
					time:5000,
					
	     		 tipsMore: true
	     		});
			}
		})
	});

</script>
</body>

</html>